import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {SideMenuService} from "../../../services/common/side-menu.service";
import {MeProvider} from "../../../providers/me/me.provider";
import {TeamMarketActivityListPage} from "../team-market-activity-list/team-market-activity-list";
import {TeamPerformanceOverviewPage} from "../team-performance-overview/team-performance-overview";
import {TeamIndexProvider} from "../../../providers/my-team/team-index/team-index.provider";
import {ToastService} from "../../../services/common/toast.service";

/**
 * 我的团队首页
 */

@IonicPage()
@Component({
    selector: 'page-team-index',
    templateUrl: 'team-index.html',
    providers: [
        SideMenuService,
        TeamIndexProvider,
        ToastService
    ]
})
export class TeamIndexPage {
    public workingNum;

    constructor(public navCtrl: NavController,
                public navParams: NavParams,
                private sideMenuService: SideMenuService,
                private toastService: ToastService,
                private teamProvider: TeamIndexProvider,) {
    }

    private isBack;
    ionViewDidLoad() {
        this.getWorkOverViewNum();
        this.isBack = this.navParams.get('isBack');
    }

    /**
     * 获取在职人力数量
     */
    getWorkOverViewNum() {
        this.teamProvider.getWorkOverView().subscribe(res => {
            this.workingNum = res;
        },error2 => {
        })
    }

    /**
     * 下拉刷新
     */
    doRefresh(refresher) {
        this.getWorkOverViewNum();
        setTimeout(() => {
            refresher.complete();
        }, 1000);
    }

    /**
     * 打开菜单
     */
    openMenu(myEvent) {
        this.sideMenuService.openSideMenu(myEvent)
    }

    /**
     *  返回
     */

    backToProPage() {
        this.navCtrl.pop(null);
    }

    /**
     * 跳转页面
     * @param pageName
     */
    goDetailPage(pageName:string,params?:any) {
        let fullRoles:Array<any> = localStorage.getItem("fullRoles").split(','),flag:boolean=false;
        fullRoles.forEach(item=>{
            if(item === '1') flag = true;
        });
        if(flag && pageName === 'TeamPerformanceOverviewPage'){//跳转内勤页面
            this.navCtrl.push('TeamPerformanceInhousePage');
        }else{
            this.navCtrl.push(pageName,{overView:'1'});
        }
    }
}
